package com.develop.wechatpay.controller;

import com.alibaba.fastjson.JSONObject;
import com.develop.wechatpay.domain.WechatPayModel;
import com.develop.wechatpay.service.WeChatPayOrderService;
import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager;
import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

//@RestController
//@RequestMapping("/order")
public class WeChatPayOrderController {


    @Autowired
    private WeChatPayOrderService weChatPayOrderService;


    @PostMapping("jsapiAddOrder")
    public JSONObject jsapiAddOrder(@RequestBody @Validated WechatPayModel wechatPayModel) throws Exception {
        return weChatPayOrderService.jsapiAddOrder(wechatPayModel);
    }

    @GetMapping("queryOrderByOutRradeNo")
    public JSONObject queryOrderByOutRradeNo(@NotNull(message = "商户订单号不能为空!") String outRradeNo) throws Exception {

        return weChatPayOrderService.queryOrderByOutRradeNo(outRradeNo);
    }

    @GetMapping("queryOrderByTransactionId")
    public JSONObject queryOrderByTransactionId(@NotNull(message = "微信支付系统生成的订单号!") String transactionId) throws Exception {
        return weChatPayOrderService.queryOrderByTransactionId(transactionId);
    }

    @GetMapping("getPaySign")
    public String getPaySign(@NotNull(message = "时间戳不能为空!") String timestamp, @NotNull(message = "随机数不能为空!") String nonceStr,
                             @NotNull(message = "预支付交易会话标识不能为空!") String prepay_id) throws Exception {
        return weChatPayOrderService.getPaySign(timestamp, nonceStr, prepay_id);
    }

    @GetMapping("getTradeBillFile")
    public JSONObject getTradeBillFile(@NotNull(message = "账单日期不能为空!") String bill_date, @NotNull(message = "账单类型不能为空!") String bill_type,
                                       @NotNull(message = "压缩类型不能为空!") String tar_type) throws Exception {
        return weChatPayOrderService.getTradeBillFile(bill_date, bill_type, tar_type);
    }

    @GetMapping("getFundFlowBillFile")
    public JSONObject getFundFlowBillFile(@NotNull(message = "账单日期不能为空!") String bill_date, @NotNull(message = "资金账户类型不能为空!") String account_type,
                                          @NotNull(message = "压缩类型不能为空!") String tar_type) throws Exception {
        return weChatPayOrderService.getFundFlowBillFile(bill_date, account_type, tar_type);
    }
}
